package com.zetyun.tiger.connector.cdc;

import java.io.IOException;
import java.io.Serializable;

public interface SimpleRedisCommandsContainer extends Serializable {

    /**
     * Open the Jedis container.
     *
     * @throws Exception if the instance can not be opened properly
     */
    void open() throws Exception;

    /**
     * Sets field in the hash stored at key to value, with TTL, if needed.
     * Setting expire time to key is optional.
     * If key does not exist, a new key holding a hash is created.
     * If field already exists in the hash, it is overwritten.
     *
     * @param key       Hash name
     * @param hashField Hash field
     * @param value     Hash value
     * @param ttl       Hash expire time
     */
    void hset(String key, String hashField, String value, Integer ttl);


    /**
     * Get field in the hash stored at key to value,
     *
     * @param key       Hash name
     * @param hashField Hash field
     */
    String hget(String key, String hashField);

    /**
     * Get the value of the specified key. If the key does not exist null is returned. If the value
     * stored at key is not a string an error is returned because GET can only handle string values.
     * <p>
     * Time complexity: O(1)
     *
     * @param key
     * @return Bulk reply
     */
    String get(String key);


    /**
     * Test for existence of a specified field in a hash. <b>Time complexity:</b> O(1)
     *
     * @param key
     * @param hashField
     * @return Return 1 if the hash stored at key contains the specified field. Return 0 if the key is
     * not found or the field is not present.
     */
    Boolean hexists(String key, String hashField);


    /**
     * Get field in the hash stored at key to value,
     *
     * @param key     Hash name
     * @param members members
     */
    Long sadd(String key, String... members);

    /**
     * Return the number of items in a hash.
     * <p>
     * <b>Time complexity:</b> O(1)
     *
     * @param key key
     * @return The number of entries (fields) contained in the hash stored at key. If the specified
     * key does not exist, 0 is returned assuming an empty hash.
     */
    Long hlen(String key);


    /**
     * set hash expire time,
     *
     * @param key     Hash name
     * @param seconds expire seconds
     */
    Long expire(String key, Integer seconds);

    /**
     * Remove the specified field from an hash stored at key.
     * <p>
     * <b>Time complexity:</b> O(1)
     *
     * @param key
     * @param fields
     * @return If the field was present in the hash it is deleted and 1 is returned, otherwise 0 is
     * returned and no operation is performed.
     */
    Long hdel(final String key, final String... fields);


    Long hincrBy(String key, String hashField, Long value, Integer ttl);


    /**
     * Add the specified member to the set stored at key.
     * Specified members that are already a member of this set are ignored.
     * If key does not exist, a new set is created before adding the specified members.
     *
     * @param setName Name of the Set
     * @param value   Value to be added
     */
    void sadd(String setName, String value, Integer ttl);

    /**
     * Remove the specified member from the set value stored at key. If member was not a member of the
     * set no operation is performed. If key does not hold a set value an error is returned.
     * <p>
     * Time complexity O(1)
     *
     * @param key
     * @param members
     * @return Integer reply, specifically: 1 if the new element was removed 0 if the new element was
     * not a member of the set
     */
    Long srem(final String key, Integer ttl, final String... members);

    /**
     * Return the set cardinality (number of elements). If the key does not exist 0 is returned, like
     * for empty sets.
     *
     * @param key
     * @return Integer reply, specifically: the cardinality (number of elements) of the set as an
     * integer.
     */
    Long scard(final String key);

    /**
     * Close the Jedis container.
     *
     * @throws IOException if the instance can not be closed properly
     */
    void close() throws IOException;
}
